// 验证规则
let reg = [
    /^[a-zA-Z][a-zA-Z0-9]{5,11}$/, //首为字母的6-12位字母数字间
    /^1[3-9]\d{9}$/,               //11位手机号
    /^\d{4}$/, //4位手机验证码
    /^\w{6,12}$/,  //6至12位的密码
]

// 鼠标在输入框失焦时验证
// 遍历
$a('.inp').forEach(function (dom, i) {
    dom.addEventListener('blur', function () {
        // 判断格式是否正确
        if (reg[i].test(dom.value)) {
            $a('.tips')[i].classList.remove('block')
        } else {
            $a('.tips')[i].classList.add('block')
        }

    });
});

// 点击复选框，注册按钮禁用解除
$('.changeBtn').addEventListener('change', function () {
    $('.now').disabled = !this.checked;
    $('.now').style.background = this.checked ? 'rgb(21, 189, 237)' : '';
    $('.now').style.color = this.checked ? ' rgb(255, 255, 255)' : '';
})

// 点击注册按钮，验证所有输入框正确性，正确跳转(只验证假)
$('.now').addEventListener('click', function () {
    for (let i = 0; i < reg.length; i++) {
        if (!reg[i].test($a('.inp')[i].value)) {
            $a('.tips')[i].classList.add('block')
            return;
        }
    }
    location.href = '../login/login.html'
})



// 输入文字，显示删除按钮，
$a('.inp').forEach(function (v, i) {
    v.addEventListener('input', function () {
        if (this.value.length > 0) {
            $a('.del')[i].classList.add('block')
        } else {
            $a('.del')[i].classList.remove('block')
        }
    })
})

// 点击删除按钮，清空input值
$a('.del').forEach(function (v, i) {
    v.addEventListener('click', function () {
        $a('.inp')[i].value = ''
        v.classList.remove('block')
    })
})